package main

import (
	"fmt"
	"github.com/wsw188440873/ctrl-cali/types"
	"math"
)

func main() {
	var test []float64
	fmt.Println(test[0])
}

//func precision(modelId string, params map[string]interface{}, collectLen int) (map[string]float64, bool) {
//	if _, ok := params["collect_data"]; !ok {
//		return nil, false
//	}
//	if _, ok := types.Range[modelId]; !ok {
//		return nil, false
//	}
//	avgParams := params["collect_data"].(map[string][]float64)
//	avgMap := make(map[string]float64) //   标准气体测量平均值
//	// 计算每一次的平均值
//	for key, values := range avgParams {
//		sum := float64(0)
//		length := 0
//		for _, v := range values {
//			length++
//			sum += v
//		}
//		//计算平均值.
//		f, _ := decimal.NewFromFloat(sum / float64(length)).Round(2).Float64()
//		avgMap[key] = f
//	}
//
//	fmt.Println("平均值:", avgMap)
//	// 计算精密度.
//	precisionMap := make(map[string]float64)
//	for key, value := range avgParams {
//		sum := float64(0)
//		avg := avgMap[key]
//		for _, v := range value {
//			vAvg, _ := decimal.NewFromFloat(v - avg).Round(2).Float64()
//			sum += vAvg
//		}
//		P, _ := decimal.NewFromFloat(math.Pow(sum, 2) / float64(len(value)-1)).Round(2).Float64()
//		sqrt, _ := decimal.NewFromFloat(math.Sqrt(P)).Round(2).Float64()
//		precisionMap[key] = sqrt
//	}
//	return precisionMap, true
//}

func precision(modelId string, params map[string]interface{}, collectLen int) (map[string]float64, bool) {
	if _, ok := params["collect_data"]; !ok {
		return nil, false
	}
	if _, ok := types.Range[modelId]; !ok {
		return nil, false
	}
	avgParams := params["collect_data"].(map[string][]float64)
	avgMap := make(map[string]float64) //   标准气体测量平均值
	// 计算每一次的平均值
	for key, values := range avgParams {
		sum := float64(0)
		length := 0
		for _, v := range values {
			length++
			sum += v
		}
		//计算平均值.
		avgMap[key] = sum / float64(length)
	}
	fmt.Println("-----测试测试:-------", avgMap)
	// 计算精密度.
	precisionMap := make(map[string]float64)
	for key, value := range avgParams {
		sum := float64(0)
		avg := avgMap[key]
		for _, v := range value {
			sum += math.Pow(v-avg, 2)
		}
		P := sum / float64(len(value)-1)
		precisionMap[key] = math.Sqrt(P)
	}
	fmt.Println("测试测试:", precisionMap)
	return precisionMap, true
}

//func main() {
//	//SetEvent()
//	//SetCaliParams()
//}

func SetEvent() {
	for i := 50; i <= 63; i += 1 {
		data := fmt.Sprintf("{Name: \"%v\", Src: []string{\"%v\"}, Dst: \"%v\"},", i, i, i+1)
		fmt.Println(data)
	}
}

func SetCaliParams() {
	for i := 50; i <= 64; i += 2 {
		data := fmt.Sprintf("\"%v\": CaliParams{GasType: 0, Number: 0.8, Ext: 30, Unit: \"PPB\", ValueTime: []int{}, EveryTime: 0},", i)
		fmt.Println(data)
		data = fmt.Sprintf("\"%v\": CaliParams{GasType: 1, Number: 0.8, Ext: 30, Unit: \"PPB\", ValueTime: []int{}, EveryTime: 0},", i+1)
		fmt.Println(data)
	}
}
